{extends file="../acp.html"}

{block name="title"}{$head_title}{/block}
{block name="content"}
<script>
    function no_pic(obj) {
        obj.setAttribute("src", "/Public/Images/acp/nopicture.jpg");
    }
</script>

<div class="tablesWrap">
    <div class="tables-searchbox">
        <form method="post">
            <span class="tbs-txt">服务商名称：</span>
            <input type="text" name="service_providers_name" value="{$service_providers_name}">

            <select name="service_type_id">
                <option value="0" selected="">-服务类型-</option>
                {foreach from=$service_type_list item=type}
                <option value="{$type.service_type_id}"{if $service_type_id EQ $type.service_type_id}selected{/if}>{$type.service_type_name} </option>
                {/foreach}
            </select>
         
            <select name="service_providers_status">
                <option value="-1" selected="">-服务商状态-</option>
                {foreach from=$providers_status item=status key=key}
                <option value="{$key}" {if $key EQ $service_providers_status}selected{/if}>{$status}</option>
                {/foreach}
            </select>

            <select name="is_recommend">
                <option value="-1" selected="">-是否推荐-</option>
                <option value="1" {if $is_recommend EQ 1}selected{/if}>是</option>
                <option value="0" {if $is_recommend EQ 0}selected{/if}>否</option>
            </select>

            <div class="mgt10">
                <span class="tbs-txt">添加时间：</span>
                <input type="text" autocomplete="off" class="Wdate" name="start_date" value="{$start_date|date_format:'%Y-%m-%d'}"  onclick="WdatePicker({ dateFmt:'yyyy-MM-dd H:mm'})">
                <span class="tbs-txt">至</span>
                <input type="text" autocomplete="off" class="Wdate" name="end_date" value="{$end_date|date_format:'%Y-%m-%d'}"  onclick="WdatePicker({ dateFmt:'yyyy-MM-dd H:mm'})">
                <button type="submit" class="btn"><i class="gicon-search"></i>搜索</button>
            </div>

        </form>
    </div>
    <!-- end tables-searchbox -->
    <table class="wxtables">
        <colgroup>
            <col width="5%">
            <col width="7%">
            <!--<col width="5%">-->
            <col width="10%">
            <col width="8%">
            <col width="11%">
            <col width="8%">
            <col width="8%">
            <col width="10%">
            <col width="10%">
            <col width="20%">
        </colgroup>
        <thead>
        <tr>
            <td>选择</td>
            <td>服务商</td>
            <!--<td>服务商图片</td>-->
            <td>联系人</td>
            <td>联系方式</td>
            <td>区域</td>
            <td>类型</td>
            <td>状态</td>
            <td>添加时间</td>
            {if $opt == 'not_pass'}<td>未通过理由</td>{else}<td>推荐</td>{/if}
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        {foreach from=$service_providers_list item=item name=list}
        <tr>
            <td><input type="checkbox" class="checkbox" value="{$item.service_providers_id}" name="a[]"></td>
            <td>{$item.service_providers_name}</td>
            <!--<td>-->
                <!--<div class="gallery">-->
                    <!--<div><img src="{$item.service_providers_logo}" style="width:70px;display:block;"/></div>-->
                    <!--<div class="clear"></div>-->
                <!--</div>-->
                <!--&lt;!&ndash;<a href="{$item.link_item}" target="_blank"><img src="{$item.small_img}" alt="" width="50" height="50" onerror="no_pic(this);"></a>&ndash;&gt;-->
            <!--</td>-->
            <td>{$item.user_name}</td>
            <td>{$item.mobile}</td>
            <td>{$item.area_string}</td>
            <td>{$item.service_type_name}</td>
            <td>{$item.status_name}</td>
            <td>{$item.addtime|date_format:"%Y-%m-%d %H:%M:%S"}</td>
            {if $opt == 'not_pass'}<td>{$item.status_cause}</td>{else}<td>{if $item.is_recommend == 1}是{else}否{/if}</td>{/if}
            <td>
                <a href="/AcpServiceProviders/edit_service_providers/service_providers_id/{$item.service_providers_id}" class="btn" title="编辑">编辑</a>
                {if $item.service_providers_status == ServiceProvidersModel::TOAUDIT}<!-- 待审核的  -->
                <a href="javascript:;" class="btn" onclick="set_status(1,{$item.service_providers_id})" title="通过">通过</a>
                <a href="javascript:;" class="btn" onclick="set_status(2,{$item.service_providers_id})" title="拒绝">拒绝</a>
                {elseif $item.service_providers_status == ServiceProvidersModel::NOTPASS}<!-- 未通过审核  -->
                <!--<a href="javascript:;" class="btn" onclick="set_status(1,{$item.service_providers_id})" title="通过">通过</a>-->
                <!-- <a href="javascript:;" class="btn" onclick="write_reason({$item.service_providers_id})" title="编写理由">编写理由</a> -->
                {elseif $item.service_providers_status == ServiceProvidersModel::APPROVED}<!-- 通过审核并上架  -->
                <a href="/AcpServiceApply/get_service_apply_list/service_providers_id/{$item.service_providers_id}" class="btn"  title="查看预约">查看预约</a>
                <a href="javascript:;" class="btn" onclick="set_status(3,{$item.service_providers_id})" title="下架">下架</a>
                {elseif $item.service_providers_status == ServiceProvidersModel::SOLDOUT}<!-- 下架的  -->
                <a href="/AcpServiceApply/get_service_apply_list/service_providers_id/{$item.service_providers_id}" class="btn"  title="查看预约">查看预约</a>
                <a href="javascript:;" class="btn" onclick="set_status(1,{$item.service_providers_id})" title="上架">上架</a>
                {/if}
                {if $item.service_providers_status != 4}
                <a href="javascript:;" class="btn " onclick="set_status(4,{$item.service_providers_id})" title="删除">删除</a>
                {/if}
            </td>
        </tr>
        {foreachelse}
        <tr><td colspan="10">没有找到任何记录</td></tr>
        {/foreach}
        </tbody>
    </table>
    <!-- end wxtables -->
    <div class="tables-btmctrl clearfix">
        <div class="fl">
            <a href="javascript:Select()" class="btn btn-blue">全选</a>
            <a href="javascript:Cancel()" class="btn btn-blue">取消</a>
            <a href="javascript:;" class="btn btn-blue " onclick="batch_set_status(3)">下架</a>
            <a href="javascript:;" class="btn btn-blue " onclick="batch_set_status(1)">上架</a>
            <a href="javascript:;" class="btn btn-blue " onclick="batch_set_status(4)">删除</a>
        </div>
        <div class="fr">
            <div class="paginate">
                {$page->show()}
            </div>
            <!-- end paginate -->
        </div>
    </div>
    <!-- end tables-btmctrl -->
</div>
<!-- end tablesWrap -->
{/block}

{block name="js"}
<script src="/Public/Plugins/My97DatePicker/WdatePicker.js?version={$version}"></script>
<script src="__ACPJS__/acp_item.js?version={$version}"></script>
<script src="__JS__/front/jquery.showLoading.min.js?version={$version}"></script>
<script src="__JS__/clipboard.min.js"></script>
<link rel="stylesheet" href="__CSS__/front/showLoading.css?version={$version}">
{literal}
<script>
    //全选
    function Select(){
        var sel=document.getElementsByName("a[]");
        for(var i=0;i<sel.length;i++){
            sel[i].checked=true;
        }
    }
    //取消全选
    function Cancel(){
        var sel=document.getElementsByName("a[]");
        for(var i=0;i<sel.length;i++){
            sel[i].checked=false;
        }
    }

</script>
<script>
    function set_status(status,service_providers_id) {
        var opt =''
        var html='';
        if(status == 1){
            opt ='通过审核/上架';
            html = '确定'+opt+'吗?';
        }else if(status == 2){
            opt ='拒绝通过';
            
            var html='<form id="reason_form">' +
                    '<div class="formitems inline">'+
                    '<label class="fi-name"><span class="colorRed">*</span>未通过理由：</label>'+
                    '<div class="form-controls">'+
                    '<textarea name="content" id="content"></textarea><span class="fi-help-text"> </span>'+
                    '</div>' +
                    '<input type="hidden" name="service_providers_id" value="'+service_providers_id+'">'+
                    '<input type="hidden" name="service_providers_status" value="'+status+'">'+
                    '<input type="hidden" name="act" value="add">'+
                    '</div>'+
                    '</form>';
        }else if(status == 3){
            opt ='下架服务商';
            html = '确定'+opt+'吗?';
        }else if(status == 4){
            opt ='删除服务商';
            html = '确定'+opt+'吗?';
        }

        // $.jPops.custom({
        //     title:'提示',
        //     content:'确定'+opt+'吗?',
        //     okBtnTxt:"确定",
        //     cancelBtnTxt:"取消",
        //     callback:function(r)
        //     {
        //         if(r)
        //         {
        //             $.post('/AcpServiceProviders/set_status',{'service_providers_id':service_providers_id,'service_providers_status':status},function(data) {
        //                 console.log(data)
        //                 if (data == 'success') {
        //                     alert('恭喜你, '+ opt +'成功');
        //                     location.reload();
        //                 } else {
        //                     alert('抱歉,'+ opt +'失败');
        //                 }
        //             });
        //         }
        //         return true;
        //     }
        // });
        // 
        // 

        $.jPops.custom({
            title:opt,
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                if(r)
                {
                    if(status != 2){
                        $.post('/AcpServiceProviders/set_status',{'service_providers_id':service_providers_id,'service_providers_status':status},function(data)
                        {
                            if (data == 'success')
                            {
                                alert('恭喜您，操作成功！');
                                location.reload();
                            }
                            else
                            {
                                alert('对不起，操作失败！');
                            }
                        })
                    }

                    if(status == 2){
                        $.validator.setDefaults(
                            {
                                //表单验证通过后的处理，异步提交表单
                                submitHandler: function()
                                {
                                    $.post('/AcpServiceProviders/set_status',$('#reason_form').serialize(),function(data)
                                    {
                                        if (data == 'success')
                                        {
                                            alert('恭喜您，操作成功！');
                                            location.reload();
                                        }
                                        else
                                        {
                                            alert('对不起，操作失败！');
                                        }
                                    })
                                    acp.batchDeliverFormStatus = true;
                                }
                            });
                        //表单验证规则
                        $("#reason_form").validate(
                                {
                                    rules:
                                    {
                                        content:
                                        {
                                            required: true
                                        }
                                    },
                                    messages:
                                    {
                                        content:
                                        {
                                            required: "对不起，请填写不通过审核的理由",
                                        }
                                    },
                                    errorPlacement: acp.form_ShowError,//显示出错信息(这段代码必须加)
                                    success:acp.form_HideError//验证成功隐藏错误信息(这段代码必须加)
                                });

                        //模拟提交表单
                        $("#reason_form").submit();
                        return acp.batchDeliverFormStatus;
                    }
                }
                else
                {
                    return true;
                }
            }
        });

    }
</script>

<script>
    function batch_set_status(status)
    {

        var opt =''
        if(status == 1){
            opt ='通过审核/上架';
        }else if(status == 3){
            opt ='下架服务商';
        }else if(status == 4){
            opt ='删除服务商';
        }

        $.jPops.confirm(
                {
                    title:"提示",
                    content:'确定'+opt+'吗?',
                    okBtnTxt:"确定",
                    cancelBtnTxt:"取消",
                    callback:function(r)
                    {
                        if(r)
                        {
                            var obj_ids = '';
                            var count = 0;
                            $('input[name="a[]"]:checked').each(function(){
                                count ++;
                                obj_ids += $(this).val() + ',';
                            });

                            if (!count)
                            {
                                alert('对不起，请选择至少一项进行'+ opt +'！');
                                return;
                            }

                            obj_ids = obj_ids.substr(0, obj_ids.length - 1);

                            $.post('/AcpServiceProviders/batch_set_status', {"obj_ids":obj_ids,"status":status}, function(data, textStatus)
                            {
                                if (data == 'success')
                                {
                                    alert('恭喜您，批量'+ opt +'成功！');
                                    location.reload();
                                }
                                else
                                {
                                    alert('对不起，批量'+ opt +'删除失败！');
                                }
                            });
                        }
                        return true;
                    }
                });
    }
</script>



<script>
    function write_reason(service_providers_id)
    {
        var html='';

        var html='<form id="reason_form">' +
                '<div class="formitems inline">'+
                '<label class="fi-name"><span class="colorRed">*</span>未通过理由：</label>'+
                '<div class="form-controls">'+
                '<textarea name="status_cause" id="status_cause"></textarea><span class="fi-help-text"> </span>'+
                '</div>' +
                '<input type="hidden" name="service_providers_id" value="'+service_providers_id+'">'+
                '<input type="hidden" name="act" value="add">'+
                '</div>'+
                '</form>';
        $.jPops.custom({
            title:"未通过理由",
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                if(r)
                {
                    $.validator.setDefaults(
                            {
                                //表单验证通过后的处理，异步提交表单
                                submitHandler: function()
                                {
                                    $.post('/AcpServiceProviders/write_reason',$('#reason_form').serialize(),function(data)
                                    {
                                        if (data == 'success')
                                        {
                                            alert('恭喜您，操作成功');
                                            location.reload();
                                        }
                                        else
                                        {
                                            alert('对不起，操作失败');
                                        }
                                    })
                                    acp.batchDeliverFormStatus = true;
                                }
                            });

                    //表单验证规则
                    $("#reason_form").validate(
                            {
                                rules:
                                {
                                    status_cause:
                                    {
                                        required: true
                                    }
                                },
                                messages:
                                {
                                    status_cause:
                                    {
                                        required: "对不起，请填写不通过审核的理由",
                                    }
                                },
                                errorPlacement: acp.form_ShowError,//显示出错信息(这段代码必须加)
                                success:acp.form_HideError//验证成功隐藏错误信息(这段代码必须加)
                            });

                    //模拟提交表单
                    $("#reason_form").submit();
                    return acp.batchDeliverFormStatus;
                }
                else
                {
                    return true;
                }
            }
        });
    }
</script>
{/literal}
{/block}
